#ifndef LOMINSTANCEFACTORYHH
#define LOMINSTANCEFACTORYHH
#include "lom-typedefs.hh"

namespace lom
{
    class LomInstance;
    class LomClass;
    class ILomEventSystem;
    /**
       Interface to the lom instance creation mechanism.
     */
    class ILomInstanceFactory
    {
    public:
	virtual ~ILomInstanceFactory() {};
	/**
	   Reserve a handle value.  This guaratees that that handle
	   value will not be used when an instance is created and the
	   reserved handle argument is zero.  The instance manager
	   should be able to put fake blank objects in place of the
	   reserved objects and then transfer the reference count over
	   to the real objects when they are created
	 */
	virtual THandle reserveHandle() = 0;
	/**
	   Create a new instance of the class with default values.
	*/
	virtual THandle createInstance( const LomClass* cls, THandle reserveHandle = 0 ) = 0;
	/**
	   Create a new instance.  If the reserve handle argument is
	   not zero, then the return handle value should be the
	   reserved handle value, else the return value should be a
	   new handle value.
	 */
	virtual THandle createInstance( const LomInstance& inst
					, THandle reservedHandle = 0 ) = 0;
    };
    
    class ILomInstanceManager;
    class ILomValueFactory;
    
    class LomInstanceFactory : public ILomInstanceFactory
    {
	ILomInstanceManager* instanceMgr;
	ILomValueFactory* valueFactory;
	ILomEventSystem* eventSys;
	
    public:
	virtual void setup( ILomInstanceManager* _instanceMgr
			    , ILomValueFactory* _valueFactory
			    , ILomEventSystem* eventSys );
	virtual ~LomInstanceFactory(){}
	virtual THandle reserveHandle();
	virtual THandle createInstance( const LomClass* cls, THandle reserveHandle = 0 );
	virtual THandle createInstance( const LomInstance& inst
					, THandle reserveHandle = 0 );
    };
}

#endif
